<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">              
    
    <ui:composition template="templatePadrao.xhtml">
        
            <ui:define name="top">       
                <ui:include src="menu.xhtml" />
            </ui:define>             
        
      <ui:define name="content">
          
       <h:form id="formMessages">
           <p:growl id="messages" widgetVar="messages" showDetail="true" life="5000" sticky="false" autoUpdate="true" />  
       </h:form>                        
            
      <body onload="unidade.show()">  
          
          <h:form id="principal" prependId="false">
              
                <p:contextMenu for=":tabela:aulas">                     
                    <p:menuitem value="Editar"  update="principal" icon="ui-icon-arrowrefresh-1-w" actionListener="#{CalculoFolhaController.editar()}"/>
                </p:contextMenu>  
              
              <p:commandButton value="Alterar Unidade" onclick="unidade.show()"/>
                                         
              <p:panelGrid columns="2" styleClass="usuarioGrid">
              
                    <p:outputLabel value="Unidade Corrente :"/>
                    <p:outputLabel value="#{CalculoFolhaController.nomeUnidade}"/>
                    
              </p:panelGrid>
              
              <p:panelGrid columns="6" styleClass="usuarioGrid">
                    <p:outputLabel value="Filtros :"/>
                    <p:selectOneMenu label="Disciplina" id="selectFiltro" value="#{CalculoFolhaController.filtroSelecionado}">
                        <p:ajax event="change" update=":principal :tabela:aulas"/>
                        <f:selectItem itemValue="0" itemLabel="Padrão"/>
                        <f:selectItem itemValue="1" itemLabel="Data"/>
                    </p:selectOneMenu>
                    <p:inputText size="11" maxlength="10" id="filtroDataIni" value="#{CalculoFolhaController.dataIniFiltro}" title="Informe a data inicial a ser fitrada" rendered="#{CalculoFolhaController.exibeDatas}" onblur="validaDataIni(this)" onkeyup="mascaraData(this)"/>
                    <p:outputLabel value="Até" rendered="#{CalculoFolhaController.exibeDatas}" />
                    <p:inputText size="11" maxlength="10" id="filtroDataFim" value="#{CalculoFolhaController.dataFimFiltro}" title="Informe a data final a ser fitrada" rendered="#{CalculoFolhaController.exibeDatas}" onblur="validaDataFim(this)" onkeyup="mascaraData(this)"/>
                    <p:commandButton value="Atualizar" update=":tabela:aulas" action="#{CalculoFolhaController.atualizaLista()}" rendered="#{CalculoFolhaController.exibeDatas}" onclick="blockPrincipal.show()" oncomplete="blockPrincipal.hide()"/>
              </p:panelGrid>
              
              <p:fieldset legend="Apontamento">
                  
                  <p:panelGrid id="padrao" columns="6" style="width: 70%;" styleClass="usuarioGrid">
                                                 
                                <h:outputLabel value="Hora Inicial :"/>                      
                                <p:inputMask mask="99:99" size="5" id="horaIni" value="#{CalculoFolhaController.horaIni}" title="Informe a hora inicial" onblur="Verifica_Hora_Ini(this)" />
                                
                                <h:outputLabel value="Hora Final :"/>                      
                                <p:inputMask mask="99:99" size="5" id="horaFim" value="#{CalculoFolhaController.horaFim}" title="Informe a hora final" onblur="Verifica_Hora_Ini(this)" />                                
                                
                                <p:selectOneMenu style="width: 200px;" label="Professor" id="selectProfessorDisciplina" value="#{CalculoFolhaController.selectedProfessorDisciplina}">                                
                                    <p:ajax event="change" update="selectDisciplina"/>
                                    <f:selectItems value="#{CalculoFolhaController.carregarProfessor}" />
                                </p:selectOneMenu>                                                                  
                                
                                <p:selectOneMenu style="width: 200px;" label="Professor" id="selectDisciplina" value="#{CalculoFolhaController.selectedDisciplina}">
                                    <p:ajax event="change" update="selectProfessorDisciplina"/>
                                    <f:selectItems value="#{CalculoFolhaController.carregarSelectDisciplina}" />
                                </p:selectOneMenu>                                 
                      
                 </p:panelGrid>                      
                  
              </p:fieldset>
              
              <p:commandButton value="Salvar" actionListener="#{CalculoFolhaController.salvar()}" update=":principal :tabela:aulas" />
              
              <p:commandButton value="Cancelar" actionListener="#{CalculoFolhaController.resetaCampos()}" update=":principal" />
              
              <p:blockUI widgetVar="blockPrincipal" block="principal" >                               
                    <p:graphicImage value="./../img/ajax-loader.gif"/>                  
              </p:blockUI>               
                                      
          </h:form>
          <h:form id="tabela" prependId="false">
             
                <p:dataTable id="aulas" var="aula" emptyMessage="Não existe grade pra essa unidade"
                             value="#{CalculoFolhaController.lista}" widgetVar="aulaTable"
                             selectionMode="single" selection="#{CalculoFolhaController.gradeHorariaSelecionada}"
                             rowKey="#{aula.id}" 
                             paginator="true" rows="30">                          
                    
                   <p:column>   
                        <f:facet name="header">  
                                <h:outputText value="Turma" />  
                        </f:facet>  
                            <h:outputText value="#{aula.turma.nome}"/>
                    </p:column>                     
                   
                    <p:column>   
                        <f:facet name="header">  
                                <h:outputText value="Disciplina" />  
                        </f:facet>  
                            <h:outputText value="#{aula.disciplina.nome}"/>
                    </p:column>                    
                    
                   <p:column filterMatchMode="contains" filterBy="#{aula.professor.nome}">   
                        <f:facet name="header">  
                                <h:outputText value="Professor" />  
                        </f:facet>  
                            <h:outputText value="#{aula.professor.nome}"/>
                    </p:column>                             
                    
                    <p:column>   
                        <f:facet name="header">  
                                <h:outputText value="Data" />  
                        </f:facet>  
                            <h:outputText value="#{aula.data}">
                                <f:convertDateTime timeZone="America/Sao_Paulo" pattern="dd/MM/yyyy"/> 
                            </h:outputText>
                    </p:column>                    

                    <p:column>                          
                            <f:facet name="header">  
                                <h:outputText value="Inicio" />  
                            </f:facet>
                                    <h:outputText value="#{aula.horaIni}">  
                                        <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                                    </h:outputText>
                                                      
                    </p:column>    
                    
                    <p:column>
                            <f:facet name="header">  
                                <h:outputText value="Fim" />  
                            </f:facet>
                                    <h:outputText id="horaFim" value="#{aula.horaFim}">  
                                        <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                                    </h:outputText>                                                      
                    </p:column>    
                    
                    <p:column>   
                        <f:facet name="header">  
                                <h:outputText value="Hora(s)" />  
                        </f:facet>                          
                            <h:outputText value="#{aula.totHrs}">
                                <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                            </h:outputText>                        
                    </p:column>    
                    
                     <p:column>   
                        <f:facet name="header">  
                                <h:outputText value="Atraso" />  
                        </f:facet>  
                            <h:outputText value="#{aula.atraso}">
                                <f:convertDateTime timeZone="America/Sao_Paulo" pattern="HH:mm"/>
                            </h:outputText>
                    </p:column>  

               </p:dataTable>                              
              
              <p:commandButton value="Editar" actionListener="#{CalculoFolhaController.editar()}" update=":principal"/>              
              <p:commandButton id="completaFolha" value="Completa Folha" update=":principal :tabela:aulas" actionListener="#{CalculoFolhaController.completaFolha()}"/>
              <p:commandButton onclick="escolherRelatorio.show()" title="Relatório" value="Relatórios"/>
              
           <h:panelGrid rendered="#{loginController.usuDir}">  
                    <p:panel header="Exportar Dados">  
                        <h:commandLink>  
                            <p:graphicImage value="./../img/excel.png" />  
                            <p:dataExporter type="xls" target="aulas" fileName="Folha" />  
                        </h:commandLink>  

                        <h:commandLink>  
                            <p:graphicImage value="./../img/pdf.png" />  
                            <p:dataExporter type="pdf" target="aulas" fileName="Folha"/>  
                        </h:commandLink>  

                    </p:panel>  
                </h:panelGrid>                                          
              
              <p:blockUI widgetVar="blockTabela" block="tabela" >                               
                    <p:graphicImage value="./../img/ajax-loader.gif"/>                  
              </p:blockUI>               
           
          </h:form>
            
        <!-- Abaixo temos o modal que irá controlar de qual unidade será apresentada a grade horária-->
        <p:dialog widgetVar="unidade" id="dialogUnidade" header="Unidades" closable="false" resizable="false" closeOnEscape="false">
       
            <h:form id="dlgUnidade" prependId="false">

                <p:panelGrid styleClass="usuarioGrid" columns="1">
                
                     <p:selectOneMenu style="width: 300px;" label="Unidade" id="selectUnidade" value="#{CalculoFolhaController.selectedUnidades}"> 
                         <f:selectItems value="#{CalculoFolhaController.carregarUnidadeDisponivel}" />                         
                     </p:selectOneMenu>                
                
                </p:panelGrid>    
                    
                <p:panelGrid columns="2" styleClass="usuarioGrid">
                    
                    <p:commandButton id="selecionaUnidade" value="Selecionar" update=":dialogUnidade :principal :tabela:aulas" actionListener="#{CalculoFolhaController.atualizaLista()}"/>
                    <p:button id="cancelar" value="Cancelar" onclick="unidade.hide()" outcome="home"/>
                                        
                </p:panelGrid>
                
            </h:form>
            
        </p:dialog> 
        
        <!-- Abaixo temos o modal que irá controlar o relatório de Recibos-->
        <p:dialog widgetVar="relatorioRecibos" id="dialogRelatorioRecibo" header="Recibos" resizable="false" closeOnEscape="false" >
       
            <h:form id="dlgRelatorioRecibo" prependId="false">
                
                <p:panelGrid styleClass="usuarioGrid" columns="2" style="width: 300px">
                    
                    <p:selectOneRadio id="tipoRecebio" value="#{CalculoFolhaController.tipoRecibo}">
                        <f:selectItem itemLabel="Mês" itemValue="mes"/>
                        <f:selectItem itemLabel="Período" itemValue="periodo"/>
                        <p:ajax event="change" update=":dlgRelatorioRecibo:filtrosRecibos"/>
                    </p:selectOneRadio>                                
                    
                </p:panelGrid>

                <p:panelGrid id="filtrosRecibos" styleClass="usuarioGrid" columns="3" style="width: 300px">
                
                    <p:inputText size="11" maxlength="10" id="relDataIni" value="#{CalculoFolhaController.relDataIni}" title="Informe a data inicial a ser fitrada" onblur="validaDataIni(this)" onkeyup="mascaraData(this)" rendered="#{CalculoFolhaController.reciboPeriodo}"/>
                    <p:outputLabel value="Até" rendered="#{CalculoFolhaController.reciboPeriodo}" />
                    <p:inputText size="11" maxlength="10" id="relDataFim" value="#{CalculoFolhaController.relDataFim}" title="Informe a data final a ser fitrada" onblur="validaDataFim(this)" onkeyup="mascaraData(this)" rendered="#{CalculoFolhaController.reciboPeriodo}"/>                                       
                    
                    <p:selectOneMenu label="mesRecibo" id="mesRecibo" value="#{CalculoFolhaController.mesFiltro}" rendered="#{CalculoFolhaController.reciboMes}">
                            <f:selectItem itemLabel="Janeiro" itemValue="0"/>
                            <f:selectItem itemLabel="Fevereiro" itemValue="1"/>
                            <f:selectItem itemLabel="Março" itemValue="2"/>
                            <f:selectItem itemLabel="Abril" itemValue="3"/>
                            <f:selectItem itemLabel="Maio" itemValue="4"/>
                            <f:selectItem itemLabel="Junho" itemValue="5"/>
                            <f:selectItem itemLabel="Julho" itemValue="6"/>
                            <f:selectItem itemLabel="Agosto" itemValue="7"/>
                            <f:selectItem itemLabel="Setembro" itemValue="8"/>
                            <f:selectItem itemLabel="Outubro" itemValue="9"/>
                            <f:selectItem itemLabel="Novembro" itemValue="10"/>
                            <f:selectItem itemLabel="Dezembro" itemValue="11"/>                        
                    </p:selectOneMenu>
                    
                </p:panelGrid>
                
                <p:panelGrid styleClass="usuarioGrid" columns="1" style="width: 300px">
                
                    <p:selectOneMenu style="width: 260px;" label="TipoContrato" id="selectTipoContrato" value="#{CalculoFolhaController.selectTipoContrato}"> 
                        <f:selectItems value="#{CalculoFolhaController.carregarTipoContrato}" />                         
                     </p:selectOneMenu> 
                    
                    <p:selectOneMenu style="width: 300px;" label="Professor" id="selectProfessor" value="#{CalculoFolhaController.selectedProfessor}">
                         <f:selectItems value="#{CalculoFolhaController.carregarSelectProfessor}" />
                     </p:selectOneMenu>                                    
                    
               </p:panelGrid>
                
                <p:panelGrid styleClass="usuarioGrid" columns="2" style="width: 300px">
                    
                             <p:outputLabel>Desconto</p:outputLabel>
                             
                             <p:inputText id="valorDesc" size="15" maxlength="15" title="Informe o valor ser descontado" onkeyup="mascara(this, valor);" value="#{CalculoFolhaController.valorDesconto}">
                                 <f:convertNumber pattern="#,##0.00"/>
                             </p:inputText>  
                             
                             <p:outputLabel>Acréscimos</p:outputLabel>
                             
                             <p:inputText id="valorEmp" size="15" maxlength="15" title="Informe o valor de empréstimo" onkeyup="mascara(this, valor);" value="#{CalculoFolhaController.valorEmprestimo}">
                                 <f:convertNumber pattern="#,##0.00"/>
                             </p:inputText>                              
                             
                </p:panelGrid>
                
                <p:panelGrid styleClass="usuarioGrid" columns="3">
                             
                    <h:outputText value="Considerar Fins de Semana ?  " />
                    <p:selectBooleanCheckbox id="selectFds" value="#{CalculoFolhaController.consideraFds}">
                        <p:ajax event="change" update=":principal :tabela:aulas"/>                        
                    </p:selectBooleanCheckbox>                    
                                        
                </p:panelGrid>    
                    
                <p:panelGrid columns="2" styleClass="usuarioGrid">
                    
                    <p:commandButton id="chamaRelatorio" value="Gerar Relatório" update=":principal :tabela:aulas" actionListener="#{CalculoFolhaController.relatorioRecibos()}" onclick="relatorioRecibos.hide()" ajax="false"/>
                    <p:button id="cancelarRelatorio" value="Cancelar" onclick="relatorioRecibos.hide()"/>                                         
                                        
                </p:panelGrid>
                
              <p:blockUI widgetVar="blockRecibo" block=":dlgRelatorioRecibo" >                               
                    <p:graphicImage value="./../img/ajax-loader.gif"/>                  
              </p:blockUI>                  
                
            </h:form>
            
        </p:dialog>     
        
        <!-- Abaixo temos o modal que irá controlar o relatório de Folha de Ponto-->
        <p:dialog widgetVar="relatorioFolhaPonto" id="dialogRelatorioFolhaPonto" header="Folha de Ponto" resizable="false" closeOnEscape="false" >
       
            <h:form id="dlgRelatorioFolhaPonto" prependId="false">
                
                <p:panelGrid styleClass="usuarioGrid" columns="2" style="width: 300px">
                    
                    <p:selectOneRadio id="tipoPonto" value="#{CalculoFolhaController.tipoPonto}">
                        <f:selectItem itemLabel="Mês" itemValue="mes"/>
                        <f:selectItem itemLabel="Período" itemValue="periodo"/>
                        <p:ajax event="change" update="dlgRelatorioFolhaPonto:filtrosPonto"/>
                    </p:selectOneRadio>                                
                    
                </p:panelGrid>

                <p:panelGrid id="filtrosPonto" styleClass="usuarioGrid" columns="3" style="width: 300px">
                
                    <p:inputText size="11" maxlength="10" id="relDataIniPonto" value="#{CalculoFolhaController.relDataIni}" title="Informe a data inicial a ser fitrada" onblur="validaDataIni(this)" onkeyup="mascaraData(this)" rendered="#{CalculoFolhaController.pontoPeriodo}"/>
                    <p:outputLabel value="Até" rendered="#{CalculoFolhaController.pontoPeriodo}" />
                    <p:inputText size="11" maxlength="10" id="relDataFimPonto" value="#{CalculoFolhaController.relDataFim}" title="Informe a data final a ser fitrada" onblur="validaDataFim(this)" onkeyup="mascaraData(this)" rendered="#{CalculoFolhaController.pontoPeriodo}"/>
                    
                    <p:selectOneMenu label="mesRecibo" id="mesReciboPonto" value="#{CalculoFolhaController.mesFiltroPonto}" rendered="#{CalculoFolhaController.pontoMes}">
                            <f:selectItem itemLabel="Janeiro" itemValue="0"/>
                            <f:selectItem itemLabel="Fevereiro" itemValue="1"/>
                            <f:selectItem itemLabel="Março" itemValue="2"/>
                            <f:selectItem itemLabel="Abril" itemValue="3"/>
                            <f:selectItem itemLabel="Maio" itemValue="4"/>
                            <f:selectItem itemLabel="Junho" itemValue="5"/>
                            <f:selectItem itemLabel="Julho" itemValue="6"/>
                            <f:selectItem itemLabel="Agosto" itemValue="7"/>
                            <f:selectItem itemLabel="Setembro" itemValue="8"/>
                            <f:selectItem itemLabel="Outubro" itemValue="9"/>
                            <f:selectItem itemLabel="Novembro" itemValue="10"/>
                            <f:selectItem itemLabel="Dezembro" itemValue="11"/>                        
                    </p:selectOneMenu>
                    
                </p:panelGrid>                
                
                <p:panelGrid styleClass="usuarioGrid" columns="1" style="width: 300px">
                
                    <p:selectOneMenu style="width: 260px;" label="TipoContrato" id="selectTipoContratoPonto" value="#{CalculoFolhaController.selectTipoContrato}">                         
                        <f:selectItem itemValue="0" itemLabel="Todos os Tipos de Contratação"/>
                        <f:selectItem itemValue="99" itemLabel="Excedente"/>
                        <f:selectItem itemValue="2" itemLabel="Carga Fechada"/>
                     </p:selectOneMenu>                     
                    
               </p:panelGrid>                
                
                <p:panelGrid styleClass="usuarioGrid" columns="3">
                             
                    <h:outputText value="Considerar Fins de Semana ?  " />
                    <p:selectBooleanCheckbox id="selectFdsPonto" value="#{CalculoFolhaController.consideraFds}">
                        <p:ajax event="change" update=":principal :tabela:aulas"/>                        
                    </p:selectBooleanCheckbox>                    
                                        
                </p:panelGrid>    
                    
                <p:panelGrid columns="2" styleClass="usuarioGrid">
                    
                    <p:commandButton id="chamaRelatorioFolhaPonto" value="Gerar Relatório" update=":principal :tabela:aulas" actionListener="#{CalculoFolhaController.relatorioFolhaPonto()}" onclick="relatorioFolhaPonto.hide()" ajax="false"/>                    
                    <p:button id="cancelarRelatorioFolhaPonto" value="Cancelar" onclick="relatorioFolhaPonto.hide()"/>                                         
                                        
                </p:panelGrid>
                
              <p:blockUI widgetVar="blockAulas" block=":dlgRelatorioFolhaPonto" >                               
                    <p:graphicImage value="./../img/ajax-loader.gif"/>                  
              </p:blockUI>                  
                
            </h:form>
            
        </p:dialog>         
        
        <p:dialog widgetVar="escolherRelatorio" id="dialogEscolhaRelatorio" header="Relatórios" resizable="false" closeOnEscape="false" >
            
            <h:form>
                
                <p:panelGrid columns="3" styleClass="usuarioGrid">
                                        
                    <p:selectOneRadio id="relatorio" value="#{CalculoFolhaController.relatorio}">
                        <f:selectItem itemLabel="Recibo" itemValue="recibo"/>
                        <f:selectItem itemLabel="Folha de Ponto" itemValue="folhaPonto"/>
                    </p:selectOneRadio>
                    
                    <p:commandButton value="Executar" onclick="escolherRelatorio.hide()" actionListener="#{CalculoFolhaController.executaRelatorio()}"/>
                    
                </p:panelGrid>                
                
            </h:form>
            
        </p:dialog>
     
        </body>
        
        </ui:define>            
   
   </ui:composition>
        
</html>